package org.mao.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

public class LoginIntercepter implements HandlerInterceptor {

	//public static final HashSet 

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// TODO Auto-generated method stub
		
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Content-type", "text/plain;charset=UTF-8");

		//requesturl = http://localhost:8090/family/css/bootstrap.css
		String requestURL = request.getRequestURL().toString();
		//System.out.println(requestURL);
		//contextpath = /family
		String contextPath = request.getContextPath() + "/";

		String urlPath = requestURL.substring(requestURL.indexOf(contextPath) + contextPath.length(), requestURL.length());

//		if (urlPath.length() > 0) {
//			UserLogin userLogin = (UserLogin) request.getSession().getAttribute(FamilyConstants.LOGIN_KEY);
//			if (userLogin == null) {
//				response.setStatus(FamilyConstants.HTTP_STATUS_NOT_LOGIN);
//			}
//		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		//ResourceHttpRequestHandler requestHandler=(ResourceHttpRequestHandler)handler;
		//requestHandler.
		//System.out.println(modelAndView);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		// TODO Auto-generated method stub

	}

}
